package com.enzoism.spring.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.context.annotation.Bean;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: springcloud-test-2
 * @description: 用户对象模型
 * @author: zhifeng
 * @create: 2020-12-07 09:46
 */
@Data
@AllArgsConstructor
public class UserModel {
    private int id;
    private int userAge;
    private String userName;

    private static List<UserModel> userList;

    public static List<UserModel> initUserList(){
        ArrayList<UserModel> userModels = new ArrayList<UserModel>();
        userModels.add(new UserModel(1,20,"JACK"));
        userModels.add(new UserModel(2,21,"TOM"));
        userModels.add(new UserModel(3,22,"JERRY"));
        userModels.add(new UserModel(4,23,"PIGGY"));
        userList = userModels;
        return userModels;
    }

    public static List<UserModel> getUserList() {
        List<UserModel> userList = initUserList();
        return UserModel.userList;
    }
    public static UserModel getUserById(String id) {
        UserModel userModel = null;
        for (int i = 0; i < userList.size(); i++) {
            userModel = userList.get(i);
            if (StringUtils.equalsIgnoreCase(id, String.valueOf(userModel.getId()))){
                return userModel;
            }
        }
        return userModel;
    }
}
